{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}

{/* Import Js,Css */}
	<css href="__PUBLIC__/Css/jquery-ui.css"/>
	<js href="__PUBLIC__/Js/core/jquery-ui.1.10.4.js"/>
	
	<js href="__PUBLIC__/Js/Function.js" />
	<js href="__PUBLIC__/Js/FileController.js" />
	<js href="__PUBLIC__/Js/ajaxupload.js" />
{/* Import Js,Css */}

<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->

<div>
	<table id="mytab"  border="1" width="100%" class="t1">
		<tr class="a1">
			<td width="50px">
				<label><input type="checkbox" />&nbsp;&nbsp;全选</label>
		  	</td>
		  	<td align="center" width="30px">
				{$lang.sort_order}
		  	</td>
		  	<td align="center">
				{$lang.audio_name}
		  	</td>
		  	<td align="center">
				{$lang.audio_url}
		  	</td>
			<td align="center">
				歌词文件路径(*.txt)
		  	</td>
		  	<td align="center">
				{$lang.action}
		  	</td>
		</tr>
	<volist name="audiolist" id="vo">
	  <tr>
		<td width="50px">
			<input type="checkbox" />
		</td>
	  	<td align="center">
	  		{$vo.sort}
	  	</td>
	  	<td align="center">
	  		{$vo.name}
	  	</td>
	  	<td align="center">
	  		{$vo.audio_url}
	  	</td>
			<td align="center">
	  		{$vo.lyric_url}
	  	</td>
	  	<td align="center">
	  		<a href="javascript:FileController.deleteMp3andRecord({$vo.id},'{$lang.confirm_text}');">{$lang.delete}</a>
	  	</td>
	  </tr>
	 </volist>
	 <tr class="a1">		
		<if condition="$audioCount neq 0">	
		<td></td>				
		<elseif condition="$audioCount eq 0"/>
		<td>{$lang.no_data}</td>
		</if>				
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td><a href="javascript:createAudioExcel('__URL__/createMp3Excel');">{$lang.create_excel}</td>	
	 </tr>
	</table>
	<div style="border:1px solid red; margin-top:10px; background:#FFD700;"> 
		<h1>Excel下载说明</h1>
		<p style="font-size:14px; color:#404040; font-family:'微软雅黑'; line-height:35px; text-indent:20px;">
				1) 所有的歌词文件都是放在 Public/Upload/music/lyric文件夹下面				
		</p>
	</div>
</div>
<form method="post" action="__APP__/Course/addmp3Ok">	
	<div class="mp20">
		<span class="dp mauto addmp3" style="margin-bottom:10px;">{$lang.add_mp3}</span>
		<table id="addmp3table"  border="1" width="100%" class="t1">
			<tr style="font-weight:600;" class="header">	
				<td align="right" width="120px">
					{$lang.audio}
				</td>
				<td align="center">
					{$lang.audio_name}
				</td>
				<td align="center">
					排序
				</td>
				<td align="left">
					{$lang.upload_text}
				</td>
			</tr>
			<tr class="values">
				<td  align="right">					
					{$lang.listen_audio}
				</td>
				<td align="left" >
					<input type="text" class="input" name="audio_name[]"/>
				</td>
				<td align="left" >
					<input type="text" class="input" name="sort[]"/>
				</td>
				<td >
					{$lang.upload_byhand}
				</td>
			</tr>	
			<tr class="addTr">
				<td colspan="4" align="center">
					<span  style="font-size:15px; font-weight:bold; cursor:pointer;" onclick="addaudio();">
						<b style="color:red;">[+]</b>
						{$lang.add}
					</span>
				</td>
			</tr>
		</table>
	</div>
	<div class="submit" style="text-align:center;">
		<input type="hidden" id="course_id" name="id" value="{$id}" />
		<input type="submit" value="{$lang.submit_text}"/>
		<input type="button" value="{$lang.reset_text}"/>			
	</div>
</form>

<script>
	/**
	 * 添加音频输入框
	 *
	 */
	function addaudio(){
		var html = '<td  align="right"><b style="color:blue; cursor:pointer;" onclick="deleteaudio(this);">[-]&nbsp;&nbsp;</b>试听音频</td>';
			html +=  '<td align="left"><input type="text" class="input" name="audio_name[]"/></td>';
			html +=  '<td align="left"><input type="text" class="input" name="sort[]"/></td>';
			html +=  '<td >手动上传</td>';		
		var table = $('#addmp3table');
		var tr    = $('<tr></tr>');
		tr.html(html);		
		table.find('tr.addTr').before(tr);		
	}
	/**
	 * 删除audio输入框
	 *
	 */
	function deleteaudio(obj){
		var tr    =   $(obj.parentNode.parentNode);
		tr.remove();		
	}
	



	FileController.deleteMp3 = function (id){
		var zip          =   document.getElementById(id);		
		var del_id       =   "del" + id;
		var delbutton    =   document.getElementById(del_id);
		var datas        =   {};
		datas['mp3']     =   zip.innerText;		
		//post 
		$.post(
			"__APP__/File/deleteMp3", 
			datas,
			function (msg){
				if( msg.data != null && msg.data  == "1" ){
					zip.innerText              =   'Upload';
					delbutton.style.display    =   'none';
				}
			}, 
			"json"
		);		
	}	
		
	FileController.deleteMp3andRecord = function(id,tips){
		//Get id
		if(typeof id == 'undefined' || id == null) { 　console.info("id参数不对"); return; }
		if(typeof tip == 'undefined') tip = '确定将数据放到回收站吗?';
		//构建对象
		var datas   =   {};
		datas['audio_id'] =   id;
		//请求用户同意
		if(confirm(tip)){
			//请求服务器
			$.extend(FileController.opt,{
				 url:'__APP__/Course/delAudio',
				 data:datas,
				 success:function(msg){
					 if(msg.data == '1'){
						 window.parent.frames['right'].location.reload();
					 }else{
						 alert("该操作失败");
					 }
				 }		
			});
			$.ajax(FileController.opt);
		}
	}
	
	/**
	 * 生成excel
	 *
	 */
	function createAudioExcel(url){
		var course_id         =      document.getElementById('course_id');
		url                  +=      "?course_id=" + course_id.value;		
		window.location.href  =      url;
	}
	
</script>


